package cn.fintecher.ams.service.attendance.exception;

import cn.fintecher.ams.service.attendance.common.ResponseResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/4/17.
 */
@RestController
@ControllerAdvice
public class ExceptionAdapter {

    private  final static Log logger = LogFactory.getLog(ExceptionAdapter.class);


    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception e){
        logger.error("",e);
        int errorCode = -999;
        String errMsg = "系统异常";
        if (e instanceof AbstractException) {
            errorCode = ((AbstractException) e).getErrorCode();
            errMsg = e.getMessage();
        }
       return ResponseResult.wrap(errorCode,errMsg);

    }

}
